import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/api/api.js'
Vue.use(Vuex)
export default  new Vuex.Store({
    state: {
      shopDetail:{

      },
      shopBigDetail:{

      },
      count: 0,  
      adminDetail:{},
       
      checkOrders:[], //开票选择
      checkGoods:[],
      messageDetail:{},
      messageNum: '',
      showIndex: false,
      myStoreId:'',
      shopList:[],
      wareDetail:{}
    },
    mutations: {
      setShopDetail(state,obj) {
        state.shopDetail = obj
      },
      setShopBigDetail(state,obj) {
        state.shopBigDetail = obj
      },
      increment (state) {
        state.count++
      },
      setShopList(state,list){
        state.chooseShopList=list
      },
      setAdminDetail(state,obj){
        state.adminDetail = obj
      },
      
      setCheckGoods(state,obj){
        state.checkGoods = obj
      },
      setCheckOrders(state,arr){
        state.checkOrders = arr
      },
      setWarehouseReple(state,obj){
        state.warehouseReple = obj
      },
      setWarehouseRepleGoods(state,arr){
        state.warehouseRepleGoods = arr
      },
      setMessageDetail(state,obj){
        state.messageDetail = obj
      },
      setMessageNum(state,num){
        state.messageNum = num
      },
      setShowIndex(state,bool){
        state.showIndex = bool
      },
      setMyStoreId(state,str){
        state.myStoreId = str
      },
      setShopList(state,ary){
        state.shopList = ary
      },
      setWareDetail(state,obj){
        state.wareDetail = obj
      },

    },
    actions:{ 
      getMessageNum(context){
        // increment (context) {
        //   context.commit('increment')
        // }
        api.messageMng.getUnReadCount({},res=>{
          context.commit('setMessageNum',res.result);
        })
      },
      getShopList(context){
        let data = {
          pageNum: 1,
          pageSize: 1000
        } 
        api.shopMng.shopList(data,res=>{ 
          const ary = res.result.data.map(item=>{
              return {
                  name: item.channelName,
                  value: item.channelId
              }
          });
          context.commit('setShopList',ary);
        })
      }
    }
  }) 